<template>
  <el-form label-width="100px" class="container">
    <el-form-item label="密码">
      <el-input type="password" v-model="password" placeholder="Enter Password..."></el-input>
    </el-form-item>
    <el-form-item>
      <el-button
          type="primary"
          class="submit-btn"
          @click="handleResetPassword"
      >
        重置密码
      </el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts">
import { ref, getCurrentInstance } from 'vue'
import { useRouter, useRoute } from 'vue-router'

export default {
  name: "ForgotPassword",
  setup() {
    const { appContext } = getCurrentInstance()
    const password = ref<string>('')

    const route = useRoute()
    const router = useRouter()
    console.log('route',route.params.id)
    const handleResetPassword = async () => {
      if (password.value) {
        const res = await appContext.config.globalProperties.$axios.put('/api/v1/auth/resetpassword' + route.params.id,
            {
              password: password.value
            })
        if (res.data.success) {
          await router.push('/')
        }
      }

    }
    return {
      password,
      handleResetPassword
    }
  }
}
</script>

<style scoped>
.container {
  width: 50%;
  margin: 200px auto;
}
.submit-btn {
  width: 100%;
}
</style>
